package com.zhuiyun.pm.sys.role.controller;

import com.zhuiyun.pm.page.PageRequest;
import com.zhuiyun.pm.result.CommonResult;
import com.zhuiyun.pm.sys.role.entity.SysRoleEntity;
import com.zhuiyun.pm.sys.role.service.SysRoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 角色管理
 * LC: 2023-03-13 09:46
 * @author Administrator
 */
@CrossOrigin
@RestController
@RequestMapping("/role")
public class SysRoleController {

    @Resource
    SysRoleService sysRoleService;
    
    /**
    * @Description 获取角色列表信息
    * @Author lzy
    * @Date 2023/3/14 19:48
    * @Return com.zhuiyun.pm.result.CommonResult
    */
    @GetMapping("/getRoleList")
    public CommonResult getRoleList() {
        return sysRoleService.getRoleList();
    }

    /**
     * 角色权限菜单树查询
     * @return
     */
    @GetMapping("/getMenuTree")
    public CommonResult  getMenuTree(String menuName){
        return CommonResult.ok(sysRoleService.getMenuTree(menuName));
    }

    /**
     * 全查+模糊查
     * @param pageRequest
     * @param roleName
     * @return
     */
    @GetMapping("/roleList")
    public CommonResult roleList(PageRequest pageRequest, String roleName){
        return CommonResult.ok(sysRoleService.roleList(pageRequest, roleName));
    }

    /**
     * 新增角色
     * @param sysRoleEntity
     * @return
     */
    @PostMapping("/saveRole")
    public CommonResult saveRole(SysRoleEntity sysRoleEntity){
        return CommonResult.ok(sysRoleService.saveRole(sysRoleEntity));
    }

    /**
     * 修改角色
     * @param sysRoleEntity
     * @return
     */
    @PutMapping("/updateRole")
    public CommonResult updateRole(SysRoleEntity sysRoleEntity){
        return CommonResult.ok(sysRoleService.updateRole(sysRoleEntity));
    }

    /**
     * 删除角色
     * @param id
     * @return
     */
    @DeleteMapping("/deleteRole")
    public CommonResult deleteRole(Integer id){
        return CommonResult.ok(sysRoleService.deleteRole(id));
    }

    /**
     * 权限修改
     * @param sysRoleEntity
     * @return
     */
    @PutMapping("/savePermissions")
    public CommonResult savePermissions(@RequestBody SysRoleEntity sysRoleEntity){
        return CommonResult.ok(sysRoleService.savePermissions(sysRoleEntity));
    }


}
